<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start;padding-right: 30px;">
      <el-date-picker
        v-model="paytime"
        style="width:40%;margin-right:20px;padding-right: 30px;"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="检定开始日期"
        endPlaceholder="检定结束日期"
        valueFormat="yyyy-MM-dd"
        clearable
      >
      </el-date-picker>
      <selectorg @getselectorgid="getselectorgid" style="padding-right: 30px;width:30%"></selectorg>
      <el-input
        placeholder="仪器设备名称"
        style="width:20%;margin-right:10px"
        v-model="ep_ename"
        clearable
      ></el-input>
      <el-input
        placeholder="管理编号"
        style="width:20%;margin-right:10px"
        v-model="managenum"
        clearable
      ></el-input>

    </el-row>
    <el-row>
      <el-input
        placeholder="溯源方式"
        style="width:20%;margin-right:10px"
        v-model="traceability"
        clearable
      ></el-input>
      <el-input
        placeholder="检定/校准单位"
        style="width:20%;margin-right:10px"
        v-model="verifiy_company"
        clearable
      ></el-input>


      <el-button size="mini" type="primary" @click="getlist(1)">查询</el-button><el-button size="mini" type="info" @click="daochu">导出</el-button><span>总金额：{{allsum}}</span>
    </el-row>
    <el-divider></el-divider>
    <ptable
      :tableData="list"

      :pagobj.sync="pagobj"
    ></ptable>
    <ptable id="tableExcel222ssss"
      :tableData="list1"
      v-show="false"
      :pagobj.sync="pagobj"
    ></ptable>
    <checksp
      :nowapprovalid="nowapprovalid"
      v-if="showresub"
      :isnew="false"
      atypeid="0101"
      :checkitem="checkitem"
      :fun="fun2"
    ></checksp>
  </div>
</template>

<script>

import ptable from '~/components/querysum/checkfee/reimtable.vue';
import selectorg from '~/components/common/selectorg.vue';
import checksp from '~/components/apply/checksp';

import FileSaver from 'file-saver';
import XLSX from 'xlsx';

export default {
  components: {
    ptable, selectorg, checksp,
  },
  data() {
    return {

      ts: this.newStore(),
      list: [],
      list1: [],
      paytime: [],

      ep_ename: '',
      managenum: '',
      traceability: '',
      verifiy_company: '',
      dept: '',
      allsum: '',
      showresub: false,
      nowapprovalid: '',
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      checkitem: {
        hash: {
          atype: '',
          id: '',
        },
      },
    };
  },
  mounted() {
    // this.getlist();
    // this.getitem();
  },
  methods: {
    daochu() {
      if (this.list1.length == 0) {
        this.$message({
          type: 'error',
          message: '导出数据为空,无法导出',
        });
        return false;
      }

      const xlsxParam = { raw: true }; // 转换成excel时，使用原始的格式
      /* generate workbook object from table */
      const wb = XLSX.utils.table_to_book(
        document.querySelector('#tableExcel222ssss'),
        xlsxParam,
      );
      console.log(wb);
      /* get binary string as output */
      const wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        bookSST: true,
        type: 'array',
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: 'application/octet-stream;charset=utf-8' }),
          'sheetjs.xlsx',
        );
      } catch (e) {
        if (typeof console !== 'undefined') console.log(e, wbout);
      }
      return wbout;
    },
    opendiag(item) {
      console.log(item);

      this.nowapprovalid = item.hash.aid;
      this.checkitem.hash.atype = '0102';
      this.checkitem.hash.id = item.hash.aid;
      this.reload('showresub');
    },
    reload(partsname) {
      // console.log(partsname);
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    getselectorgid(val) {
      this.dept = val;
    },

    // 获取列表
    getlist(p) {
      if (p) {
        this.pagobj.currentPage3 = p;
      }
      if (!this.paytime) {
        this.paytime = ['', ''];
      }
      // console.log("2222");
      const req = {
        handle: 'E0E144082D7A10B2DC400B628CBD4AE84E96A5409018C56964EDEA66339D7026',
        verifiytime_begin: this.paytime[0],
        verifiytime_end: this.paytime[1],

        ep_ename: this.ep_ename,
        managenum: this.managenum,
        dept: this.dept,
        traceability: this.traceability,
        verifiy_company: this.verifiy_company,
        start: (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize,
        limit: this.pagobj.pagesize,


      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.list = ts.d.data.operation1;
          this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
          this.allsum = ts.d.data.operation2[0].hash.allsum;
        }
      });
      req.limit = 100000;
      req.start = 0;
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.list1 = ts.d.data.operation1;
        }
      });
    },
  },
};
</script>

